<?php
/**
 * RUBIK IT Solution & Development ltd.
 *
 * PROJECT		: Rubik Ultimate
 * @version 	: 1.1
 * COPYRIGHT	: 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * @author			hoadn <hoadn@rubik.com.vn>
 * @access			[public/private]
 * @package		 [package name]
 *
 * Created on	:Sep 19, 2008
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

RCoreImporter::cls('html.fieldInfo.AbstractHtmlFieldInfo');
RCoreImporter::cls('html.HtmlSqlLevelCombobox');

class SqlTreeComboboxHtmlFieldInfo extends AbstractHtmlFieldInfo {

	/**
	 * @var HtmlSqlLevelCombobox
	 */
	var $_sqlCbx = null;
	
	var $_sql = null;
	var $_parentId = null;
	var $_orderBy = null;
	
	var $_ignoreId = null;
	var $_isMultiSelect = false;
	
	var $_emptyText = '- - Select please - -';
	
	/**
	 * Constructor
	 *
	 * @param string $basicName
	 */
	function __construct($basicName, $linkRule = null) {
		parent::__construct($basicName, $linkRule);
		
		$this->_sqlCbx = new HtmlSqlLevelCombobox($basicName, null);
	}
	
	/**
	 * Set Prefix for Mutilanguage
	 *
	 * @param str $prefix
	 */
	function setNamePrefix($prefix) {
		$this->_fieldName = $prefix . $this->_fieldName;
		$this->_sqlCbx = new HtmlSqlLevelCombobox($this->_fieldName, null);
	}
	
	/**
	 * Set SQL value
	 *
	 * @param string $sql
	 * @param string $parentId
	 * @param string $orderBy
	 */
	function setSQL($sql, $parentId, $orderBy = '') {
		$this->_sql = $sql;
		$this->_parentId = $parentId;
		$this->_orderBy = $orderBy;
	}
	
	/**
	 * Set the text for empty value.
	 * if the text is null --> there isn't any empty value
	 *
	 * @param string $text
	 */
	function setEmptyText($text=null) {
		$this->_emptyText = $text;
	}
	
	/**
	 * Set the select box type with multiple value
	 *
	 * @param boolean $bool
	 */
	function setMultipleSelect($bool = true) {
		$this->_isMultiSelect = $bool;
		$sqlCbx = &$this->_sqlCbx;
		$sqlCbx->setMultipleSelect($this->_isMultiSelect);
	}
	
	/**
	 * Function for geting the html for inputing data
	 *
	 * @abstract 
	 * @return string
	 */
	function getHtmlInputData($dataType = '', $extAttribute = '') {
		$sqlCbx = &$this->_sqlCbx;
		$sqlCbx->setIgnoreId($this->_ignoreId);
		$sqlCbx->setInfo($this->_sql, $this->_parentId, $this->_orderBy);
		$sqlCbx->setMultipleSelect($this->_isMultiSelect);
		$extAttribute .= $this->buildValidateHtmlAttribute($dataType);
		return $sqlCbx->createCombobox($this->_emptyText, null, null, null, null, $extAttribute);
	}
	
	/**
	 * Set the value
	 *
	 */
	function setValue($valueOrArrayContain = null) {
		$sqlCbx = &$this->_sqlCbx;
		$sqlCbx->setValue($valueOrArrayContain);
		parent::setValue($valueOrArrayContain);
	}
	
	/**
	 * Set ignore id
	 *
	 * @param int $ignoreId
	 */
	function setIgnoreId($ignoreId) {
		$this->_ignoreId = $ignoreId;
	}
}
?>